package com.chinatelecom.telecollege.sellerrewarding.service;

import com.chinatelecom.telecollege.sellerrewarding.Entity.seller;
import com.chinatelecom.telecollege.sellerrewarding.repository.sellerRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * Created by lenovo on 2017/6/21.
 */
@Service
public class sellerService {
    @Autowired
    private sellerRepo sellerRepo;

    @Transactional
    public seller find(String phone) {
        return sellerRepo.findByPhone(phone);
    }
    public List<seller> findAll() {
        return sellerRepo.findAll();
    }
    public void mod(String phone, boolean isadmin, boolean isassistant) {
        seller seller = sellerRepo.findByPhone(phone);
        seller.setIsadmin(isadmin);
        seller.setIsassistant(isassistant);
        sellerRepo.save(seller);
    }
    public void save(String phone, String name, String password, boolean isadmin, boolean isassistant) {
        seller seller = new seller();
        seller.setPhone(phone);
        seller.setName(name);
        seller.setPassword(password);
        seller.setIsadmin(isadmin);
        seller.setIsassistant(isassistant);
        sellerRepo.save(seller);
    }
    public void delete(seller seller) {
        sellerRepo.delete(seller);
    }
}
